<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>六子棋游戏</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            margin: 0;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }
        
        .game-container {
            text-align: center;
            background: rgba(255, 255, 255, 0.1);
            padding: 30px;
            border-radius: 20px;
            backdrop-filter: blur(10px);
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
        }
        
        h1 {
            margin-bottom: 20px;
            font-size: 2.5em;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
        }
        
        .game-info {
            margin-bottom: 20px;
            font-size: 1.2em;
        }
        
        .board {
            display: inline-block;
            position: relative;
            background: #8B4513;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
        }
        
        .board-grid {
            position: relative;
            width: 300px;
            height: 300px;
        }
        
        .line {
            position: absolute;
            background: #2C1810;
        }
        
        .line.horizontal {
            height: 2px;
            width: 100%;
        }
        
        .line.vertical {
            width: 2px;
            height: 100%;
        }
        
        .intersection {
            position: absolute;
            width: 20px;
            height: 20px;
            border-radius: 50%;
            border: 2px solid #444;
            background: transparent;
            cursor: pointer;
            transform: translate(-50%, -50%);
            transition: all 0.2s ease;
        }
        
        .intersection:hover {
            background: rgba(255, 255, 255, 0.3);
            transform: translate(-50%, -50%) scale(1.2);
        }
        
        .intersection.black {
            background: #000;
            border-color: #333;
        }
        
        .intersection.white {
            background: #fff;
            border-color: #ccc;
        }
        
        .intersection.marked {
            opacity: 0.8;
        }
        
        .intersection.marked::before {
            content: '✕';
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            color: #ff0000;
            font-size: 16px;
            font-weight: bold;
            text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.8);
            z-index: 10;
            pointer-events: none;
        }
        
        .intersection.selected {
            box-shadow: 0 0 15px #00ff00;
            transform: translate(-50%, -50%) scale(1.3);
        }
        
        .controls {
            margin-top: 20px;
        }
        
        button {
            background: linear-gradient(45deg, #FF6B6B, #4ECDC4);
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 25px;
            cursor: pointer;
            font-size: 16px;
            margin: 0 10px;
            transition: transform 0.2s ease;
        }
        
        button:hover {
            transform: translateY(-2px);
        }
        
        button:disabled {
            opacity: 0.5;
            cursor: not-allowed;
            transform: none;
        }
        
        .status {
            margin-top: 15px;
            font-size: 1.1em;
            font-weight: bold;
        }
        
        .eating-mode {
            background: rgba(255, 0, 0, 0.2);
            padding: 10px;
            border-radius: 10px;
            margin: 10px 0;
        }
    </style>
</head>
<body>
    <div class="game-container">
        <h1>六子棋游戏</h1>
        <div class="game-info">
            <div>当前玩家: <span id="current-player">黑子 (你)</span></div>
            <div>游戏阶段: <span id="game-phase">落子阶段</span></div>
            <div>黑子数量: <span id="black-count">0</span> | 白子数量: <span id="white-count">0</span></div>
        </div>
        
        <div id="eating-notification" class="eating-mode" style="display: none;">
            <div>可以吃子！请点击要吃掉的对方棋子</div>
            <div>可吃子数: <span id="eat-count">0</span></div>
        </div>
        
        <div class="board">
            <div class="board-grid" id="board">
                <!-- 横线 -->
                <div class="line horizontal" style="top: 0%"></div>
                <div class="line horizontal" style="top: 20%"></div>
                <div class="line horizontal" style="top: 40%"></div>
                <div class="line horizontal" style="top: 60%"></div>
                <div class="line horizontal" style="top: 80%"></div>
                <div class="line horizontal" style="top: 100%"></div>
                
                <!-- 竖线 -->
                <div class="line vertical" style="left: 0%"></div>
                <div class="line vertical" style="left: 20%"></div>
                <div class="line vertical" style="left: 40%"></div>
                <div class="line vertical" style="left: 60%"></div>
                <div class="line vertical" style="left: 80%"></div>
                <div class="line vertical" style="left: 100%"></div>
            </div>
        </div>
        
        <div class="controls">
            <button onclick="resetGame()">重新开始</button>
            <button id="skip-eat" onclick="skipEating()" style="display: none;">跳过吃子</button>
        </div>
        
        <div class="status" id="status">点击交叉点落子</div>
    </div>

    <script>
        // 音效系统
        const audioContext = new (window.AudioContext || window.webkitAudioContext)();
        
        // 生成音效
        function playSound(frequency, duration, type = 'sine', volume = 0.3) {
            const oscillator = audioContext.createOscillator();
            const gainNode = audioContext.createGain();
            
            oscillator.connect(gainNode);
            gainNode.connect(audioContext.destination);
            
            oscillator.frequency.setValueAtTime(frequency, audioContext.currentTime);
            oscillator.type = type;
            
            gainNode.gain.setValueAtTime(0, audioContext.currentTime);
            gainNode.gain.linearRampToValueAtTime(volume, audioContext.currentTime + 0.01);
            gainNode.gain.exponentialRampToValueAtTime(0.001, audioContext.currentTime + duration);
            
            oscillator.start(audioContext.currentTime);
            oscillator.stop(audioContext.currentTime + duration);
        }
        
        // 不同的音效
        const sounds = {
            place: () => playSound(800, 0.15, 'sine', 0.2), // 落子声
            move: () => playSound(600, 0.12, 'triangle', 0.15), // 移动声
            eat: () => playSound(400, 0.3, 'sawtooth', 0.25), // 吃子声
            success: () => { // 成功吃子连击声
                playSound(523, 0.1, 'sine', 0.2); // C
                setTimeout(() => playSound(659, 0.1, 'sine', 0.2), 100); // E
                setTimeout(() => playSound(784, 0.2, 'sine', 0.25), 200); // G
            },
            formation: () => { // 成上音效
                playSound(698, 0.2, 'sine', 0.3); // F
                setTimeout(() => playSound(880, 0.3, 'sine', 0.35), 150); // A
            },
            sixUp: () => { // 六上音效
                playSound(523, 0.15, 'sine', 0.25); // C
                setTimeout(() => playSound(659, 0.15, 'sine', 0.25), 100); // E
                setTimeout(() => playSound(784, 0.15, 'sine', 0.25), 200); // G
                setTimeout(() => playSound(1047, 0.25, 'sine', 0.3), 300); // C高音
            },
            warning: () => playSound(300, 0.5, 'square', 0.3), // 威胁警告声
            gameEnd: () => { // 游戏结束声
                playSound(523, 0.2, 'sine', 0.3);
                setTimeout(() => playSound(440, 0.2, 'sine', 0.3), 200);
                setTimeout(() => playSound(349, 0.4, 'sine', 0.3), 400);
            },
            victory: () => { // 胜利声
                playSound(523, 0.15, 'sine', 0.25); // C
                setTimeout(() => playSound(659, 0.15, 'sine', 0.25), 150); // E
                setTimeout(() => playSound(784, 0.15, 'sine', 0.25), 300); // G
                setTimeout(() => playSound(1047, 0.3, 'sine', 0.3), 450); // C
            }
        };
        
        // 初始化音频上下文（需要用户交互）
        function initAudio() {
            if (audioContext.state === 'suspended') {
                audioContext.resume();
            }
        }
        
        // 游戏状态
        let gameState = {
            board: Array(6).fill().map(() => Array(6).fill(0)), // 0: 空, 1: 黑子, 2: 白子, -1: 被标记吃掉的黑子, -2: 被标记吃掉的白子
            currentPlayer: 1, // 1: 黑子(玩家), 2: 白子(AI)
            phase: 'placing', // 'placing': 落子阶段, 'removing': 提子阶段, 'moving': 走子阶段
            selectedPiece: null, // 走子阶段选中的棋子
            eatingMode: false, // 是否在吃子模式
            canEat: 0, // 可以吃的子数
            totalMoves: 0,
            lastFormations: new Map(), // 记录最近的成型，防止反复成型
            moveHistory: [], // 移动历史
            removingPhase: { // 提子阶段状态
                active: false,
                playerRemoved: false,
                aiRemoved: false
            }
        };

        // 初始化棋盘
        function initBoard() {
            const board = document.getElementById('board');
            // 清除现有的交叉点
            const existingIntersections = board.querySelectorAll('.intersection');
            existingIntersections.forEach(el => el.remove());
            
            // 创建交叉点
            for (let row = 0; row < 6; row++) {
                for (let col = 0; col < 6; col++) {
                    const intersection = document.createElement('div');
                    intersection.className = 'intersection';
                    intersection.style.left = `${col * 20}%`;
                    intersection.style.top = `${row * 20}%`;
                    intersection.dataset.row = row;
                    intersection.dataset.col = col;
                    intersection.onclick = () => handleIntersectionClick(row, col);
                    board.appendChild(intersection);
                }
            }
        }

        // 处理交叉点点击
        function handleIntersectionClick(row, col) {
            // 初始化音频上下文
            initAudio();
            
            if (gameState.currentPlayer !== 1) return; // 只在玩家回合响应点击

            if (gameState.eatingMode) {
                handleEating(row, col);
                return;
            }

            if (gameState.phase === 'placing') {
                handlePlacing(row, col);
            } else if (gameState.phase === 'removing') {
                handleRemoving(row, col);
            } else if (gameState.phase === 'moving') {
                handleMoving(row, col);
            }
        }

        // 处理落子
        function handlePlacing(row, col) {
            if (gameState.board[row][col] !== 0) return;

            gameState.board[row][col] = gameState.currentPlayer;
            gameState.totalMoves++;
            sounds.place(); // 播放落子音效
            updateDisplay();

            // 检查是否可以吃子
            const eatCount = checkEating(row, col, gameState.currentPlayer);
            if (eatCount > 0) {
                gameState.eatingMode = true;
                gameState.canEat = eatCount;
                
                // 播放相应的音效和显示提示
                if (eatCount === 1) {
                    sounds.formation(); // 成上音效
                    document.getElementById('status').textContent = '恭喜！您成上了！可以吃掉对方1个棋子';
                } else if (eatCount >= 2) {
                    sounds.sixUp(); // 六上音效
                    document.getElementById('status').textContent = '太棒了！您六上了！可以吃掉对方2个棋子';
                }
                
                updateEatingNotification();
                return;
            }

            // 检查是否棋盘已满
            if (gameState.totalMoves === 36) {
                startMovingPhase();
                return;
            }

            switchPlayer();
        }

        // 处理走子
        function handleMoving(row, col) {
            if (gameState.selectedPiece) {
                // 尝试移动
                const [fromRow, fromCol] = gameState.selectedPiece;
                if (canMove(fromRow, fromCol, row, col)) {
                    // 检查是否是反复成型
                    if (isRepetitiveFormation(fromRow, fromCol, row, col, gameState.currentPlayer)) {
                        document.getElementById('status').textContent = '不能反复移动同一棋子造成重复成型！';
                        sounds.warning();
                        return;
                    }
                    
                    gameState.board[row][col] = gameState.board[fromRow][fromCol];
                    gameState.board[fromRow][fromCol] = 0;
                    gameState.selectedPiece = null;
                    
                    // 记录移动历史
                    const moveKey = `${fromRow},${fromCol}-${row},${col}`;
                    gameState.moveHistory.push(moveKey);
                    if (gameState.moveHistory.length > 8) {
                        gameState.moveHistory.shift();
                    }
                    
                    sounds.move(); // 播放移动音效
                    updateDisplay();

                    // 检查是否可以吃子
                    const eatCount = checkEating(row, col, gameState.currentPlayer);
                    if (eatCount > 0) {
                        gameState.eatingMode = true;
                        gameState.canEat = eatCount;
                        
                        // 播放相应的音效和显示提示
                        if (eatCount === 1) {
                            sounds.formation(); // 成上音效
                            document.getElementById('status').textContent = '恭喜！您移动成上了！可以吃掉对方1个棋子';
                        } else if (eatCount >= 2) {
                            sounds.sixUp(); // 六上音效
                            document.getElementById('status').textContent = '太棒了！您移动六上了！可以吃掉对方2个棋子';
                        }
                        
                        updateEatingNotification();
                        return;
                    }

                    switchPlayer();
                } else {
                    // 取消选择或选择新棋子
                    if (gameState.board[row][col] === gameState.currentPlayer) {
                        gameState.selectedPiece = [row, col];
                        updateDisplay();
                    } else {
                        gameState.selectedPiece = null;
                        updateDisplay();
                    }
                }
            } else {
                // 选择棋子
                if (gameState.board[row][col] === gameState.currentPlayer) {
                    gameState.selectedPiece = [row, col];
                    updateDisplay();
                }
            }
        }

        // 处理吃子
        function handleEating(row, col) {
            const opponent = gameState.currentPlayer === 1 ? 2 : 1;
            const cell = gameState.board[row][col];
            
            if (gameState.phase === 'placing') {
                // 落子阶段：标记被吃的子
                if (cell === opponent) {
                    // 检查目标棋子是否参与成上或六上
                    if (isPartOfFormation(row, col, opponent)) {
                        document.getElementById('status').textContent = '不能吃掉已成上或六上的棋子！';
                        sounds.warning();
                        return;
                    }
                    
                    gameState.board[row][col] = -opponent;
                    gameState.canEat--;
                    sounds.eat(); // 播放吃子音效
                    updateDisplay();
                    updateEatingNotification();
                    
                    if (gameState.canEat === 0) {
                        gameState.eatingMode = false;
                        document.getElementById('eating-notification').style.display = 'none';
                        
                        // 检查是否棋盘已满
                        if (gameState.totalMoves === 36) {
                            startMovingPhase();
                            return;
                        }
                        
                        switchPlayer();
                    }
                }
            } else {
                // 走子阶段：直接消失
                if (cell === opponent) {
                    // 检查目标棋子是否参与成上或六上
                    if (isPartOfFormation(row, col, opponent)) {
                        document.getElementById('status').textContent = '不能吃掉已成上或六上的棋子！';
                        sounds.warning();
                        return;
                    }
                    
                    gameState.board[row][col] = 0;
                    gameState.canEat--;
                    sounds.eat(); // 播放吃子音效
                    updateDisplay();
                    updateEatingNotification();
                    
                    if (gameState.canEat === 0) {
                        gameState.eatingMode = false;
                        document.getElementById('eating-notification').style.display = 'none';
                        
                        // 检查游戏是否结束
                        if (checkGameEnd()) return;
                        
                        switchPlayer();
                    }
                }
            }
        }

        // 检查是否可以移动
        function canMove(fromRow, fromCol, toRow, toCol) {
            if (gameState.board[toRow][toCol] !== 0) return false;
            
            const rowDiff = Math.abs(toRow - fromRow);
            const colDiff = Math.abs(toCol - fromCol);
            
            return (rowDiff === 1 && colDiff === 0) || (rowDiff === 0 && colDiff === 1);
        }

        // 检查指定位置的棋子是否参与成上或六上
        function isPartOfFormation(row, col, player) {
            // 检查是否参与成上（4点成格）
            const squarePositions = [
                [[row-1, col-1], [row-1, col], [row, col-1], [row, col]],
                [[row-1, col], [row-1, col+1], [row, col], [row, col+1]],
                [[row, col-1], [row, col], [row+1, col-1], [row+1, col]],
                [[row, col], [row, col+1], [row+1, col], [row+1, col+1]]
            ];
            
            for (const square of squarePositions) {
                if (square.every(([r, c]) => r >= 0 && r < 6 && c >= 0 && c < 6)) {
                    const values = square.map(([r, c]) => gameState.board[r][c]);
                    if (values.every(v => v === player)) {
                        return true; // 参与成上
                    }
                }
            }
            
            // 检查是否参与六上（6点成线）
            const linePositions = [
                // 水平线
                [[row, 0], [row, 1], [row, 2], [row, 3], [row, 4], [row, 5]],
                // 垂直线
                [[0, col], [1, col], [2, col], [3, col], [4, col], [5, col]]
            ];
            
            for (const line of linePositions) {
                const values = line.map(([r, c]) => gameState.board[r][c]);
                if (values.every(v => v === player)) {
                    return true; // 参与六上
                }
            }
            
            return false;
        }
        
        // 检查对方即将成上或六上的威胁位置
        function findThreats(player) {
            const threats = [];
            const opponent = player === 1 ? 2 : 1;
            
            for (let row = 0; row < 6; row++) {
                for (let col = 0; col < 6; col++) {
                    if (gameState.board[row][col] === 0) {
                        // 模拟对方在此位置落子
                        if (checkEating(row, col, opponent) > 0) {
                            threats.push([row, col]);
                        }
                    }
                }
            }
            
            return threats;
        }

        // 检查吃子
        function checkEating(row, col, player) {
            let squares = 0; // 成上数量
            let lines = 0;   // 六上数量
            
            // 检查四个小方格 ("成上")
            const squarePositions = [
                [[row-1, col-1], [row-1, col], [row, col-1], [row, col]],
                [[row-1, col], [row-1, col+1], [row, col], [row, col+1]],
                [[row, col-1], [row, col], [row+1, col-1], [row+1, col]],
                [[row, col], [row, col+1], [row+1, col], [row+1, col+1]]
            ];
            
            for (const square of squarePositions) {
                if (square.every(([r, c]) => r >= 0 && r < 6 && c >= 0 && c < 6)) {
                    // 检查是否所有位置都是当前玩家的棋子（不包括被标记的）
                    const values = square.map(([r, c]) => gameState.board[r][c]);
                    if (values.every(v => v === player)) {
                        squares++;
                    }
                }
            }
            
            // 检查六条直线 ("六上")
            const linePositions = [
                // 水平线
                [[row, 0], [row, 1], [row, 2], [row, 3], [row, 4], [row, 5]],
                // 垂直线
                [[0, col], [1, col], [2, col], [3, col], [4, col], [5, col]]
            ];
            
            for (const line of linePositions) {
                // 检查是否所有位置都是当前玩家的棋子（不包括被标记的）
                const values = line.map(([r, c]) => gameState.board[r][c]);
                if (values.every(v => v === player)) {
                    lines++;
                }
            }
            
            // 计算总吃子数：多个成上只算1个，六上算2个
            let totalEat = 0;
            if (squares > 0) totalEat += 1; // 不管多少个成上，只能吃1个
            if (lines > 0) totalEat += lines * 2; // 每个六上吃2个
            
            return totalEat;
        }

        // 开始走子阶段
        function startMovingPhase() {
            // 检查是否有被标记的死子
            let hasMarkedPieces = false;
            for (let row = 0; row < 6; row++) {
                for (let col = 0; col < 6; col++) {
                    if (gameState.board[row][col] < 0) {
                        hasMarkedPieces = true;
                        break;
                    }
                }
                if (hasMarkedPieces) break;
            }
            
            if (hasMarkedPieces) {
                // 有被标记的死子，正常清除后开始走子
                for (let row = 0; row < 6; row++) {
                    for (let col = 0; col < 6; col++) {
                        if (gameState.board[row][col] < 0) {
                            gameState.board[row][col] = 0;
                        }
                    }
                }
                
                gameState.phase = 'moving';
                gameState.currentPlayer = 1; // 玩家先手
                updateDisplay();
                document.getElementById('status').textContent = '走子阶段：点击你的棋子选择，然后点击相邻空位移动';
            } else {
                // 没有被标记的死子，需要进入提子阶段
                gameState.phase = 'removing';
                gameState.removingPhase.active = true;
                gameState.removingPhase.playerRemoved = false;
                gameState.removingPhase.aiRemoved = false;
                gameState.currentPlayer = 1; // 玩家先提子
                updateDisplay();
                document.getElementById('status').textContent = '提子阶段：棋盘无死子，双方各提走对方一子。请点击AI的白子提走';
            }
        }

        // 检查游戏结束
        function checkGameEnd() {
            let blackCount = 0, whiteCount = 0;
            for (let row = 0; row < 6; row++) {
                for (let col = 0; col < 6; col++) {
                    if (gameState.board[row][col] === 1) blackCount++;
                    if (gameState.board[row][col] === 2) whiteCount++;
                }
            }
            
            if (blackCount === 0) {
                document.getElementById('status').textContent = '游戏结束！白子(AI)获胜！';
                sounds.gameEnd(); // 播放游戏结束音效
                return true;
            } else if (whiteCount === 0) {
                document.getElementById('status').textContent = '游戏结束！黑子(你)获胜！';
                sounds.victory(); // 播放胜利音效
                return true;
            }
            
            return false;
        }

        // 切换玩家
        function switchPlayer() {
            gameState.currentPlayer = gameState.currentPlayer === 1 ? 2 : 1;
            updateDisplay();
            
            if (gameState.currentPlayer === 2) {
                // 检查AI是否被堵死
                if (gameState.phase === 'moving' && !hasValidMoves(2)) {
                    document.getElementById('status').textContent = 'AI被堵死，跳过回合';
                    setTimeout(() => {
                        gameState.currentPlayer = 1;
                        updateDisplay();
                    }, 1500);
                    return;
                }
                setTimeout(aiMove, 1000);
            } else if (gameState.currentPlayer === 1) {
                // 检查玩家是否被堵死
                if (gameState.phase === 'moving' && !hasValidMoves(1)) {
                    document.getElementById('status').textContent = '您被堵死，跳过回合';
                    setTimeout(() => {
                        gameState.currentPlayer = 2;
                        updateDisplay();
                        setTimeout(aiMove, 1000);
                    }, 1500);
                    return;
                }
            }
        }

        // AI移动
        function aiMove() {
            if (gameState.currentPlayer !== 2) return;

            if (gameState.eatingMode) {
                aiEat();
                return;
            }

            if (gameState.phase === 'placing') {
                aiPlace();
            } else if (gameState.phase === 'removing') {
                aiRemovePiece();
            } else if (gameState.phase === 'moving') {
                aiMovePhase();
            }
        }

        // AI落子
        function aiPlace() {
            const bestMove = findBestPlaceMove();
            if (bestMove) {
                const [row, col] = bestMove;
                gameState.board[row][col] = 2;
                gameState.totalMoves++;
                sounds.place(); // AI落子音效
                updateDisplay();

                // 检查是否可以吃子
                const eatCount = checkEating(row, col, 2);
                if (eatCount > 0) {
                    gameState.eatingMode = true;
                    gameState.canEat = eatCount;
                    
                    // 播放相应的音效和显示提示
                    if (eatCount === 1) {
                        sounds.formation(); // 成上音效
                        document.getElementById('status').textContent = 'AI成上了！可以吃掉您的1个棋子';
                    } else if (eatCount >= 2) {
                        sounds.sixUp(); // 六上音效
                        document.getElementById('status').textContent = 'AI六上了！可以吃掉您的2个棋子';
                    }
                    
                    setTimeout(aiEat, 500);
                    return;
                }

                // 检查是否棋盘已满
                if (gameState.totalMoves === 36) {
                    startMovingPhase();
                    return;
                }

                switchPlayer();
            }
        }

        // AI走子
        function aiMovePhase() {
            const bestMove = findBestMove();
            if (bestMove) {
                const [[fromRow, fromCol], [toRow, toCol]] = bestMove;
                gameState.board[toRow][toCol] = gameState.board[fromRow][fromCol];
                gameState.board[fromRow][fromCol] = 0;
                
                // 记录AI的移动历史
                const moveKey = `${fromRow},${fromCol}-${toRow},${toCol}`;
                gameState.moveHistory.push(moveKey);
                if (gameState.moveHistory.length > 8) {
                    gameState.moveHistory.shift();
                }
                
                sounds.move(); // AI移动音效
                updateDisplay();

                // 检查是否可以吃子
                const eatCount = checkEating(toRow, toCol, 2);
                if (eatCount > 0) {
                    gameState.eatingMode = true;
                    gameState.canEat = eatCount;
                    
                    // 播放相应的音效和显示提示
                    if (eatCount === 1) {
                        sounds.formation(); // 成上音效
                        document.getElementById('status').textContent = 'AI移动成上了！可以吃掉您的1个棋子';
                    } else if (eatCount >= 2) {
                        sounds.sixUp(); // 六上音效
                        document.getElementById('status').textContent = 'AI移动六上了！可以吃掉您的2个棋子';
                    }
                    
                    setTimeout(aiEat, 500);
                    return;
                }

                switchPlayer();
            } else {
                // AI无法移动，跳过回合
                setTimeout(() => {
                    switchPlayer();
                }, 1000);
            }
        }

        // 寻找最佳落子位置（改进版）
        function findBestPlaceMove() {
            const emptySpots = [];
            for (let row = 0; row < 6; row++) {
                for (let col = 0; col < 6; col++) {
                    if (gameState.board[row][col] === 0) {
                        emptySpots.push([row, col]);
                    }
                }
            }

            if (emptySpots.length === 0) return null;

            // 策略1: 寻找能立即吃子的位置
            for (const [row, col] of emptySpots) {
                if (checkEating(row, col, 2) > 0) {
                    return [row, col];
                }
            }

            // 策略2: 优先阻止玩家的直接威胁（最重要！）
            const playerThreats = findAllThreats(1);
            if (playerThreats.length > 0) {
                // 优先阻止六上威胁，再阻止成上威胁
                for (const threat of playerThreats) {
                    const [threatRow, threatCol] = threat.position;
                    if (emptySpots.some(([r, c]) => r === threatRow && c === threatCol)) {
                        console.log(`AI阻止玩家${threat.type === 'line' ? '六上' : '成上'}威胁于位置(${threatRow + 1}, ${threatCol + 1})`);
                        return [threatRow, threatCol];
                    }
                }
            }

            // 策略3: 阻止玩家一般的吃子机会
            for (const [row, col] of emptySpots) {
                if (checkEating(row, col, 1) > 0) {
                    return [row, col];
                }
            }

            // 策略4: 选择最有价值的位置
            let bestSpot = null;
            let bestScore = -1;
            
            for (const [row, col] of emptySpots) {
                const score = evaluatePlacePosition(row, col, 2);
                if (score > bestScore) {
                    bestScore = score;
                    bestSpot = [row, col];
                }
            }

            return bestSpot || emptySpots[Math.floor(Math.random() * emptySpots.length)];
        }

        // 寻找最佳移动（改进版）
        function findBestMove() {
            // 首先检查是否被堵死
            if (!hasValidMoves(2)) {
                document.getElementById('status').textContent = 'AI被堵死，跳过回合';
                return null;
            }

            const aiPieces = [];
            for (let row = 0; row < 6; row++) {
                for (let col = 0; col < 6; col++) {
                    if (gameState.board[row][col] === 2) {
                        aiPieces.push([row, col]);
                    }
                }
            }
            
            const possibleMoves = [];
            for (const [row, col] of aiPieces) {
                const moves = [
                    [row-1, col], [row+1, col], [row, col-1], [row, col+1]
                ];
                for (const [newRow, newCol] of moves) {
                    if (newRow >= 0 && newRow < 6 && newCol >= 0 && newCol < 6 && 
                        gameState.board[newRow][newCol] === 0) {
                        
                        // 检查是否是反复成型
                        if (!isRepetitiveFormation(row, col, newRow, newCol, 2)) {
                            possibleMoves.push([[row, col], [newRow, newCol]]);
                        }
                    }
                }
            }

            if (possibleMoves.length === 0) {
                document.getElementById('status').textContent = 'AI无法移动，跳过回合';
                return null;
            }

            // 策略1: 寻找能立即吃子的移动
            for (const [[fromRow, fromCol], [toRow, toCol]] of possibleMoves) {
                // 模拟移动
                const originalValue = gameState.board[fromRow][fromCol];
                gameState.board[fromRow][fromCol] = 0;
                gameState.board[toRow][toCol] = originalValue;
                
                const eatCount = checkEating(toRow, toCol, 2);
                
                // 恢复棋盘
                gameState.board[toRow][toCol] = 0;
                gameState.board[fromRow][fromCol] = originalValue;
                
                if (eatCount > 0) {
                    return [[fromRow, fromCol], [toRow, toCol]];
                }
            }

            // 策略2: 阻止玩家的直接威胁
            const playerThreats = findAllThreats(1);
            if (playerThreats.length > 0) {
                for (const threat of playerThreats) {
                    const [threatRow, threatCol] = threat.position;
                    for (const [[fromRow, fromCol], [toRow, toCol]] of possibleMoves) {
                        if (toRow === threatRow && toCol === threatCol) {
                            console.log(`AI移动阻止玩家${threat.type === 'line' ? '六上' : '成上'}威胁`);
                            return [[fromRow, fromCol], [toRow, toCol]];
                        }
                    }
                }
            }

            // 策略3: 选择最有价值的移动
            let bestMove = null;
            let bestScore = -1;
            
            for (const [[fromRow, fromCol], [toRow, toCol]] of possibleMoves) {
                const score = evaluateMovePosition(fromRow, fromCol, toRow, toCol, 2);
                if (score > bestScore) {
                    bestScore = score;
                    bestMove = [[fromRow, fromCol], [toRow, toCol]];
                }
            }

            return bestMove || possibleMoves[Math.floor(Math.random() * possibleMoves.length)];
        }

        // 评估落子位置的价值
        function evaluatePlacePosition(row, col, player) {
            let score = 0;
            
            // 中心位置更有价值
            const centerDistance = Math.abs(row - 2.5) + Math.abs(col - 2.5);
            score += (5 - centerDistance) * 2;
            
            // 检查能形成多少个潜在的小方格
            const squares = [
                [[row-1, col-1], [row-1, col], [row, col-1], [row, col]],
                [[row-1, col], [row-1, col+1], [row, col], [row, col+1]],
                [[row, col-1], [row, col], [row+1, col-1], [row+1, col]],
                [[row, col], [row, col+1], [row+1, col], [row+1, col+1]]
            ];
            
            for (const square of squares) {
                if (square.every(([r, c]) => r >= 0 && r < 6 && c >= 0 && c < 6)) {
                    let friendlyCount = 0;
                    let enemyCount = 0;
                    let emptyCount = 0;
                    
                    for (const [r, c] of square) {
                        const value = Math.abs(gameState.board[r][c]);
                        if (value === player) friendlyCount++;
                        else if (value === (3 - player)) enemyCount++;
                        else emptyCount++;
                    }
                    
                    // 如果这个方格没有敌方棋子，就有潜力
                    if (enemyCount === 0) {
                        score += friendlyCount * 3 + emptyCount;
                    }
                }
            }
            
            // 检查能形成的直线潜力
            const lines = [
                [[row, 0], [row, 1], [row, 2], [row, 3], [row, 4], [row, 5]],
                [[0, col], [1, col], [2, col], [3, col], [4, col], [5, col]]
            ];
            
            for (const line of lines) {
                let friendlyCount = 0;
                let enemyCount = 0;
                
                for (const [r, c] of line) {
                    const value = Math.abs(gameState.board[r][c]);
                    if (value === player) friendlyCount++;
                    else if (value === (3 - player)) enemyCount++;
                }
                
                // 如果这条线没有敌方棋子，就有潜力
                if (enemyCount === 0) {
                    score += friendlyCount * 2;
                }
            }
            
            return score;
        }

        // 评估移动位置的价值
        function evaluateMovePosition(fromRow, fromCol, toRow, toCol, player) {
            // 模拟移动
            const originalValue = gameState.board[fromRow][fromCol];
            gameState.board[fromRow][fromCol] = 0;
            gameState.board[toRow][toCol] = originalValue;
            
            let score = evaluatePlacePosition(toRow, toCol, player);
            
            // 额外考虑：移动后是否能威胁对方
            let threats = 0;
            const adjacentPositions = [
                [toRow-1, toCol], [toRow+1, toCol], [toRow, toCol-1], [toRow, toCol+1]
            ];
            
            for (const [r, c] of adjacentPositions) {
                if (r >= 0 && r < 6 && c >= 0 && c < 6 && gameState.board[r][c] === 0) {
                    if (checkEating(r, c, player) > 0) {
                        threats++;
                    }
                }
            }
            score += threats * 5;
            
            // 恢复棋盘
            gameState.board[toRow][toCol] = 0;
            gameState.board[fromRow][fromCol] = originalValue;
            
            return score;
        }

        // 智能吃子策略
        function aiEat() {
            const opponents = [];
            for (let row = 0; row < 6; row++) {
                for (let col = 0; col < 6; col++) {
                    const cell = gameState.board[row][col];
                    if ((gameState.phase === 'placing' && cell === 1) || 
                        (gameState.phase === 'moving' && cell === 1)) {
                        // 只选择未成上或六上的棋子
                        if (!isPartOfFormation(row, col, 1)) {
                            opponents.push([row, col]);
                        }
                    }
                }
            }
            
            if (opponents.length > 0 && gameState.canEat > 0) {
                // 智能选择要吃的棋子
                let bestTarget = null;
                let bestScore = -1;
                
                for (const [row, col] of opponents) {
                    const score = evaluateEatingTarget(row, col);
                    if (score > bestScore) {
                        bestScore = score;
                        bestTarget = [row, col];
                    }
                }
                
                const [row, col] = bestTarget || opponents[Math.floor(Math.random() * opponents.length)];
                
                if (gameState.phase === 'placing') {
                    gameState.board[row][col] = -1;
                    sounds.eat(); // AI吃子音效
                    document.getElementById('status').textContent = `AI吃掉了位置(${row + 1}, ${col + 1})的黑子！还可以吃 ${gameState.canEat - 1} 个`;
                } else {
                    gameState.board[row][col] = 0;
                    sounds.eat(); // AI吃子音效
                    document.getElementById('status').textContent = `AI直接消灭了位置(${row + 1}, ${col + 1})的黑子！还可以吃 ${gameState.canEat - 1} 个`;
                }
                
                gameState.canEat--;
                updateDisplay();
                
                if (gameState.canEat > 0) {
                    setTimeout(aiEat, 800);
                } else {
                    gameState.eatingMode = false;
                    
                    if (gameState.phase === 'placing') {
                        if (gameState.totalMoves === 36) {
                            startMovingPhase();
                            return;
                        }
                    } else {
                        if (checkGameEnd()) return;
                    }
                    
                    setTimeout(() => {
                        switchPlayer();
                    }, 1000);
                }
            } else if (gameState.canEat > 0) {
                // 如果没有可吃的棋子（都已成上或六上），跳过吃子
                document.getElementById('status').textContent = 'AI无法吃子：所有对方棋子都已成上或六上！';
                gameState.eatingMode = false;
                gameState.canEat = 0;
                
                if (gameState.phase === 'placing') {
                    if (gameState.totalMoves === 36) {
                        startMovingPhase();
                        return;
                    }
                } else {
                    if (checkGameEnd()) return;
                }
                
                setTimeout(() => {
                    switchPlayer();
                }, 1000);
            }
        }

        // 评估吃子目标的价值
        function evaluateEatingTarget(row, col) {
            let score = 0;
            
            // 优先吃掉关键位置的棋子
            const centerDistance = Math.abs(row - 2.5) + Math.abs(col - 2.5);
            score += (5 - centerDistance);
            
            // 优先吃掉能阻止玩家形成威胁的棋子
            const adjacentPositions = [
                [row-1, col], [row+1, col], [row, col-1], [row, col+1]
            ];
            
            for (const [r, c] of adjacentPositions) {
                if (r >= 0 && r < 6 && c >= 0 && c < 6) {
                    // 如果附近有玩家的其他棋子，优先级更高
                    if (gameState.board[r][c] === 1) {
                        score += 3;
                    }
                }
            }
            
            return score;
        }

        // 跳过吃子
        function skipEating() {
            gameState.eatingMode = false;
            gameState.canEat = 0;
            document.getElementById('eating-notification').style.display = 'none';
            
            if (gameState.phase === 'placing' && gameState.totalMoves === 36) {
                startMovingPhase();
                return;
            }
            
            if (gameState.phase === 'moving' && checkGameEnd()) return;
            
            switchPlayer();
        }

        // 更新显示
        function updateDisplay() {
            // 更新交叉点显示
            const intersections = document.querySelectorAll('.intersection');
            intersections.forEach((intersection, index) => {
                const row = Math.floor(index / 6);
                const col = index % 6;
                const value = gameState.board[row][col];
                
                intersection.className = 'intersection';
                if (value === 1) intersection.classList.add('black');
                else if (value === 2) intersection.classList.add('white');
                else if (value === -1) {
                    intersection.classList.add('black', 'marked');
                } else if (value === -2) {
                    intersection.classList.add('white', 'marked');
                }
                
                // 显示选中的棋子
                if (gameState.selectedPiece && 
                    gameState.selectedPiece[0] === row && 
                    gameState.selectedPiece[1] === col) {
                    intersection.classList.add('selected');
                }
            });
            
            // 更新游戏信息
            document.getElementById('current-player').textContent = 
                gameState.currentPlayer === 1 ? '黑子 (你)' : '白子 (AI)';
            
            // 根据阶段显示不同信息
            if (gameState.phase === 'placing') {
                document.getElementById('game-phase').textContent = '落子阶段';
            } else if (gameState.phase === 'removing') {
                document.getElementById('game-phase').textContent = '提子阶段';
            } else if (gameState.phase === 'moving') {
                document.getElementById('game-phase').textContent = '走子阶段';
            }
            
            // 计算棋子数量
            let blackCount = 0, whiteCount = 0;
            for (let row = 0; row < 6; row++) {
                for (let col = 0; col < 6; col++) {
                    const value = Math.abs(gameState.board[row][col]);
                    if (value === 1) blackCount++;
                    else if (value === 2) whiteCount++;
                }
            }
            document.getElementById('black-count').textContent = blackCount;
            document.getElementById('white-count').textContent = whiteCount;
            
            // 更新状态文本
            if (!gameState.eatingMode && gameState.phase !== 'removing') {
                if (gameState.phase === 'placing') {
                    document.getElementById('status').textContent = 
                        gameState.currentPlayer === 1 ? '轮到你落子' : 'AI正在思考...';
                } else if (gameState.phase === 'moving') {
                    document.getElementById('status').textContent = 
                        gameState.currentPlayer === 1 ? '点击你的棋子选择，然后点击相邻空位移动' : 'AI正在移动...';
                }
            }
        }

        // 更新吃子通知
        function updateEatingNotification() {
            const notification = document.getElementById('eating-notification');
            const skipBtn = document.getElementById('skip-eat');
            
            if (gameState.eatingMode && gameState.currentPlayer === 1) {
                notification.style.display = 'block';
                skipBtn.style.display = 'inline-block';
                document.getElementById('eat-count').textContent = gameState.canEat;
            } else {
                notification.style.display = 'none';
                skipBtn.style.display = 'none';
            }
        }

        // 重置游戏
        function resetGame() {
            // 初始化音频
            initAudio();
            
            gameState = {
                board: Array(6).fill().map(() => Array(6).fill(0)),
                currentPlayer: 1,
                phase: 'placing',
                selectedPiece: null,
                eatingMode: false,
                canEat: 0,
                totalMoves: 0,
                lastFormations: new Map(),
                moveHistory: [],
                removingPhase: {
                    active: false,
                    playerRemoved: false,
                    aiRemoved: false
                }
            };
            
            // 播放重置音效
            playSound(440, 0.1, 'sine', 0.2);
            setTimeout(() => playSound(523, 0.15, 'sine', 0.25), 100);
            
            updateDisplay();
            document.getElementById('eating-notification').style.display = 'none';
            document.getElementById('status').textContent = '点击交叉点落子';
        }

        // 检查指定位置能否形成成上或六上（更详细的威胁分析）
        function analyzePosition(row, col, player) {
            let squareThreats = 0;
            let lineThreats = 0;
            let criticalMoves = [];
            
            // 分析成上威胁
            const squarePositions = [
                [[row-1, col-1], [row-1, col], [row, col-1], [row, col]],
                [[row-1, col], [row-1, col+1], [row, col], [row, col+1]],
                [[row, col-1], [row, col], [row+1, col-1], [row+1, col]],
                [[row, col], [row, col+1], [row+1, col], [row+1, col+1]]
            ];
            
            for (const square of squarePositions) {
                if (square.every(([r, c]) => r >= 0 && r < 6 && c >= 0 && c < 6)) {
                    let playerPieces = 0;
                    let emptySpaces = 0;
                    let opponentPieces = 0;
                    
                    for (const [r, c] of square) {
                        const value = gameState.board[r][c];
                        if (value === player) playerPieces++;
                        else if (value === 0) emptySpaces++;
                        else if (Math.abs(value) === (3 - player)) opponentPieces++;
                    }
                    
                    // 如果有3个己方棋子和1个空位，这是立即威胁
                    if (playerPieces === 3 && emptySpaces === 1 && opponentPieces === 0) {
                        squareThreats++;
                        // 找到关键位置
                        for (const [r, c] of square) {
                            if (gameState.board[r][c] === 0) {
                                criticalMoves.push([r, c, 'square']);
                            }
                        }
                    }
                }
            }
            
            // 分析六上威胁
            const linePositions = [
                [[row, 0], [row, 1], [row, 2], [row, 3], [row, 4], [row, 5]],
                [[0, col], [1, col], [2, col], [3, col], [4, col], [5, col]]
            ];
            
            for (const line of linePositions) {
                let playerPieces = 0;
                let emptySpaces = 0;
                let opponentPieces = 0;
                
                for (const [r, c] of line) {
                    const value = gameState.board[r][c];
                    if (value === player) playerPieces++;
                    else if (value === 0) emptySpaces++;
                    else if (Math.abs(value) === (3 - player)) opponentPieces++;
                }
                
                // 如果有5个己方棋子和1个空位，这是立即威胁
                if (playerPieces === 5 && emptySpaces === 1 && opponentPieces === 0) {
                    lineThreats++;
                    // 找到关键位置
                    for (const [r, c] of line) {
                        if (gameState.board[r][c] === 0) {
                            criticalMoves.push([r, c, 'line']);
                        }
                    }
                }
            }
            
            return { squareThreats, lineThreats, criticalMoves };
        }
        
        // 找到所有玩家的威胁位置（改进版）
        function findAllThreats(player) {
            const allThreats = [];
            
            for (let row = 0; row < 6; row++) {
                for (let col = 0; col < 6; col++) {
                    if (gameState.board[row][col] === 0) {
                        const analysis = analyzePosition(row, col, player);
                        if (analysis.squareThreats > 0 || analysis.lineThreats > 0) {
                            allThreats.push({
                                position: [row, col],
                                priority: analysis.lineThreats * 2 + analysis.squareThreats,
                                type: analysis.lineThreats > 0 ? 'line' : 'square'
                            });
                        }
                    }
                }
            }
            
            // 按优先级排序
            return allThreats.sort((a, b) => b.priority - a.priority);
        }
        
        // 检查是否有棋子可以移动
        function hasValidMoves(player) {
            for (let row = 0; row < 6; row++) {
                for (let col = 0; col < 6; col++) {
                    if (gameState.board[row][col] === player) {
                        const moves = [
                            [row-1, col], [row+1, col], [row, col-1], [row, col+1]
                        ];
                        for (const [newRow, newCol] of moves) {
                            if (newRow >= 0 && newRow < 6 && newCol >= 0 && newCol < 6 && 
                                gameState.board[newRow][newCol] === 0) {
                                return true;
                            }
                        }
                    }
                }
            }
            return false;
        }
        
        // 检查移动是否会造成反复成型
        function isRepetitiveFormation(fromRow, fromCol, toRow, toCol, player) {
            const moveKey = `${fromRow},${fromCol}-${toRow},${toCol}`;
            const reverseKey = `${toRow},${toCol}-${fromRow},${fromCol}`;
            
            // 检查历史记录中是否有相反的移动
            const recentMoves = gameState.moveHistory.slice(-4); // 检查最近4步
            return recentMoves.some(move => move === reverseKey);
        }

        // 处理提子阶段
        function handleRemoving(row, col) {
            const opponent = gameState.currentPlayer === 1 ? 2 : 1;
            const cell = gameState.board[row][col];
            
            // 玩家只能提AI的棋子，AI只能提玩家的棋子
            if (cell !== opponent) {
                document.getElementById('status').textContent = '请点击对方的棋子进行提取！';
                sounds.warning();
                return;
            }
            
            // 检查这个棋子是否参与成上或六上
            if (isPartOfFormation(row, col, opponent)) {
                document.getElementById('status').textContent = '不能提取已成上或六上的棋子！';
                sounds.warning();
                return;
            }
            
            // 提取棋子
            gameState.board[row][col] = 0;
            sounds.eat(); // 播放提子音效
            updateDisplay();
            
            if (gameState.currentPlayer === 1) {
                gameState.removingPhase.playerRemoved = true;
                document.getElementById('status').textContent = `您提走了位置(${row + 1}, ${col + 1})的白子。AI正在选择提子...`;
                
                // 检查是否双方都提完了
                if (gameState.removingPhase.aiRemoved) {
                    // 双方都提完，开始走子阶段
                    setTimeout(() => {
                        startActualMovingPhase();
                    }, 1000);
                } else {
                    // 轮到AI提子
                    setTimeout(() => {
                        aiRemovePiece();
                    }, 1500);
                }
            }
        }
        
        // AI智能提子
        function aiRemovePiece() {
            const bestTarget = findBestRemovalTarget();
            if (bestTarget) {
                const [row, col] = bestTarget;
                gameState.board[row][col] = 0;
                sounds.eat();
                updateDisplay();
                
                gameState.removingPhase.aiRemoved = true;
                document.getElementById('status').textContent = `AI提走了您位置(${row + 1}, ${col + 1})的黑子。`;
                
                // 检查是否双方都提完了
                if (gameState.removingPhase.playerRemoved) {
                    // 双方都提完，开始走子阶段
                    setTimeout(() => {
                        startActualMovingPhase();
                    }, 1000);
                } else {
                    // 等待玩家提子
                    gameState.currentPlayer = 1;
                    updateDisplay();
                    document.getElementById('status').textContent = '轮到您提子：请点击AI的白子提走';
                }
            }
        }
        
        // 寻找最佳提子目标
        function findBestRemovalTarget() {
            const playerPieces = [];
            for (let row = 0; row < 6; row++) {
                for (let col = 0; col < 6; col++) {
                    if (gameState.board[row][col] === 1) {
                        // 只能提取未成上或六上的棋子
                        if (!isPartOfFormation(row, col, 1)) {
                            playerPieces.push([row, col]);
                        }
                    }
                }
            }
            
            if (playerPieces.length === 0) return null;
            
            let bestTarget = null;
            let bestScore = -1;
            
            // 评估每个可提取棋子的价值
            for (const [row, col] of playerPieces) {
                const score = evaluateRemovalTarget(row, col);
                if (score > bestScore) {
                    bestScore = score;
                    bestTarget = [row, col];
                }
            }
            
            return bestTarget || playerPieces[Math.floor(Math.random() * playerPieces.length)];
        }
        
        // 评估提子目标的价值
        function evaluateRemovalTarget(row, col) {
            let score = 0;
            
            // 1. 优先提取关键位置的棋子（中心位置更重要）
            const centerDistance = Math.abs(row - 2.5) + Math.abs(col - 2.5);
            score += (5 - centerDistance) * 2;
            
            // 2. 评估提取后对AI的战略优势
            // 模拟提取这个棋子
            const originalValue = gameState.board[row][col];
            gameState.board[row][col] = 0;
            
            // 计算AI在各个位置的潜在威胁增加
            let threatIncrease = 0;
            for (let r = 0; r < 6; r++) {
                for (let c = 0; c < 6; c++) {
                    if (gameState.board[r][c] === 0) {
                        const aiThreats = checkEating(r, c, 2);
                        if (aiThreats > 0) {
                            threatIncrease += aiThreats;
                        }
                    }
                }
            }
            score += threatIncrease * 5;
            
            // 3. 评估是否破坏了玩家的潜在威胁
            let playerThreatReduction = 0;
            for (let r = 0; r < 6; r++) {
                for (let c = 0; c < 6; c++) {
                    if (gameState.board[r][c] === 0) {
                        // 检查原来玩家在这里的威胁
                        gameState.board[row][col] = originalValue; // 临时恢复
                        const beforeThreats = checkEating(r, c, 1);
                        gameState.board[row][col] = 0; // 再次移除
                        const afterThreats = checkEating(r, c, 1);
                        
                        if (beforeThreats > afterThreats) {
                            playerThreatReduction += (beforeThreats - afterThreats);
                        }
                    }
                }
            }
            score += playerThreatReduction * 4;
            
            // 4. 检查提取后AI的移动自由度
            let mobilityIncrease = 0;
            for (let r = 0; r < 6; r++) {
                for (let c = 0; c < 6; c++) {
                    if (gameState.board[r][c] === 2) {
                        const moves = [
                            [r-1, c], [r+1, c], [r, c-1], [r, c+1]
                        ];
                        for (const [newR, newC] of moves) {
                            if (newR >= 0 && newR < 6 && newC >= 0 && newC < 6 && 
                                gameState.board[newR][newC] === 0) {
                                mobilityIncrease++;
                            }
                        }
                    }
                }
            }
            score += mobilityIncrease * 0.5;
            
            // 恢复棋盘
            gameState.board[row][col] = originalValue;
            
            return score;
        }
        
        // 正式开始走子阶段
        function startActualMovingPhase() {
            gameState.phase = 'moving';
            gameState.removingPhase.active = false;
            gameState.currentPlayer = 1; // 玩家先手
            updateDisplay();
            document.getElementById('status').textContent = '走子阶段：点击你的棋子选择，然后点击相邻空位移动';
        }

        // 初始化游戏
        initBoard();
        updateDisplay();
    </script>
</body>
</html> 